package zpin.action;

import zpin.dao.AuthorizationDao;
import zpin.dao.CityDao;
import zpin.dao.CompanyDao;
import zpin.dao.EngageDao;
import zpin.dao.PersonDao;
import zpin.dao.ResumeDao;
import zpin.dao.RoleDao;
import zpin.dao.TypeDao;
import zpin.model.Authorization;
import zpin.model.Company;
import zpin.model.Person;

import com.opensymphony.xwork2.ActionSupport;

public class PersonAction extends ActionSupport{
	
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	private Person person;
	
	private Company company;
	
	private Authorization authorization;
	
	private PersonDao personDao;
	
	private CompanyDao companyDao;
	
	private AuthorizationDao authorizationDao;
	
	private CityDao cityDao;
	
	private EngageDao engageDao;
	
	private ResumeDao resumeDao;
	
	private RoleDao roleDao;
	
	private TypeDao typeDao;
	
	public CityDao getCityDao() {
		return cityDao;
	}

	public void setCityDao(CityDao cityDao) {
		this.cityDao = cityDao;
	}

	public EngageDao getEngageDao() {
		return engageDao;
	}

	public void setEngageDao(EngageDao engageDao) {
		this.engageDao = engageDao;
	}

	public ResumeDao getResumeDao() {
		return resumeDao;
	}

	public void setResumeDao(ResumeDao resumeDao) {
		this.resumeDao = resumeDao;
	}

	public RoleDao getRoleDao() {
		return roleDao;
	}

	public void setRoleDao(RoleDao roleDao) {
		this.roleDao = roleDao;
	}

	public TypeDao getTypeDao() {
		return typeDao;
	}

	public void setTypeDao(TypeDao typeDao) {
		this.typeDao = typeDao;
	}

	public Person getPerson() {
		return person;
	}

	public void setPerson(Person person) {
		this.person = person;
	}

	public Authorization getAuthorization() {
		return authorization;
	}

	public void setAuthorization(Authorization authorization) {
		this.authorization = authorization;
	}

	public PersonDao getPersonDao() {
		return personDao;
	}

	public void setPersonDao(PersonDao personDao) {
		this.personDao = personDao;
	}

	public AuthorizationDao getAuthorizationDao() {
		return authorizationDao;
	}

	public void setAuthorizationDao(AuthorizationDao authorizationDao) {
		this.authorizationDao = authorizationDao;
	}
	public Company getCompany() {
		return company;
	}

	public void setCompany(Company company) {
		this.company = company;
	}

	public CompanyDao getCompanyDao() {
		return companyDao;
	}

	public void setCompanyDao(CompanyDao companyDao) {
		this.companyDao = companyDao;
	}
	
	public String start(){
		Authorization authorization = new Authorization();
		authorization.setAccount("admin");
		authorization.setPassword("password");
		
		authorizationDao.saveOrUpdate(authorization);
		return SUCCESS;
	}
	
	public String login(){
		System.out.println("开始注册");
		if(person!=null){
			System.out.println("注册个人,个人的email是："+person.getEmail());
			System.out.println("账号密码为："+authorization.getAccount()+"|"+authorization.getPassword());
			person.setAuthorization(authorization);
			authorizationDao.saveOrUpdate(authorization);
			
			personDao.saveOrUpdate(person);
		}
		if(company!=null){
			System.out.println("注册公司");
			System.out.println("公司为："+company);
			System.out.println("账号密码为"+authorization);
			System.out.println("账号DAO为："+authorizationDao);
			System.out.println("公司DAO为："+companyDao);
			
			System.out.println("公司信息为："+company.getName());
			
			company.setAuthorization(authorization);
			authorizationDao.saveOrUpdate(authorization);
			companyDao.saveOrUpdate(company);
		}
		
		return SUCCESS;
	}
	
	public String toLogin(){
		return SUCCESS;
	}
	
	public String load(){
		return SUCCESS;
	}
	
	public String toLoad(){
		return SUCCESS;
	}
	
	public String function(){
		return SUCCESS;
	}
}
